package com.thon.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thon.dao.system.SystemDicDao;
import com.thon.dao.system.SystemDicDataDao;
import com.thon.dao.util.Page;
import com.thon.entity.system.SystemDic;
import com.thon.entity.system.SystemDicData;
import com.thon.service.system.SystemDicService;

@Service
@Transactional
public class SystemDicServiceImpl implements SystemDicService{

	@Autowired
	private SystemDicDao sysDicDao;	
	
	@Autowired
	private SystemDicDataDao sysDicDataDao;	


	@Override
	public SystemDic read(Integer id) {		
		
	    return sysDicDao.get(id);
	}

	@Override
	public String create(SystemDic SystemDic) {
		String msg = "success";		
		sysDicDao.save(SystemDic);
		return msg;
	}

	@Override
	public String delete(Integer id) {
		String msg = "success";		
		sysDicDao.delete(id);
		return msg;
	}

	@Override
	public String update(SystemDic systemDic) {
		String msg = "success";		
		sysDicDao.update(systemDic);
		return msg;
	}

	@Override
	public List<SystemDic> readList() {
	
			return sysDicDao.readList();
	
	}

	@Override
	public Page<SystemDic> readListPage(Integer pageNo, Integer pageSize) {
		Page<SystemDic> page = new Page<SystemDic>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);		
		return sysDicDao.readListPage(page);
	}
	
	@Override
	public Page<SystemDicData> selectDicDataListPage(String by, Object val,
			Integer pageNo, Integer pageSize) {
		Page<SystemDicData> page = new Page<SystemDicData>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);	
		page.desc("sort");
		return sysDicDataDao.readListPage(page,by,val);
	}

	@Override
	public SystemDicData readDicData(Integer id) {
		 return sysDicDataDao.get(id);
	}

	@Override
	public List<SystemDicData> readDicDataList() {
		return sysDicDataDao.readList();
	}

	@Override
	public Page<SystemDicData> readDicDataListPage(Integer pageNo,
			Integer pageSize) {
		Page<SystemDicData> page = new Page<SystemDicData>();
		page.setPageNo(pageNo);
		page.setPageSize(pageSize);
		page.desc("sort");
		return sysDicDataDao.readListPage(page);
	}

	@Override
	public String createDicData(SystemDicData systemDic) {
		String msg = "success";		
		sysDicDataDao.save(systemDic);
		return msg;
	}

	@Override
	public String deleteDicData(Integer id) {
		String msg = "success";		
		sysDicDataDao.delete(id);
		return msg;
	}

	@Override
	public String updateDicData(SystemDicData systemDic) {
		String msg = "success";		
		sysDicDataDao.update(systemDic);
		return msg;
	}

	@Override
	public List<SystemDicData> getDicData(String by, Object val) {
		SystemDic systemDic = sysDicDao.getOne(by,val);
		if(systemDic==null)
			return null;		
		return sysDicDataDao.readList("systemDic.id", systemDic.getId());
	}

	@Override
	public boolean checkSystemDicUnique(String by, Object val) {
		if(null==sysDicDao.getOne(by, val))
			return true;
		else
			return false;
	}

	@Override
	public boolean checkSystemDicDataUnique(String by, Object val) {
		if(null==sysDicDataDao.getOne(by, val))
			return true;
		else
			return false;
	}




	


}